package br.com.werp.suporte.Empresa;

import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import com.egen.util.jdbc.*;
import com.egen.util.text.*;

/**
 * Creation Date 17/12/2004 15:51:20
 * Last Modify Date 26/12/2006 10:35:12
 */

public class CargoFuncionarioAction extends com.egen.util.struts.AbstractAction {

  public ActionForward perform_insert_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    com.egen.util.jdbc.JdbcUtil j = null;
    try {
      j = new com.egen.util.jdbc.JdbcUtil();
      insert_action(j, mapping, form, request, response);
      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              com.egen.util.system.Error.getMessage(e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          com.egen.util.system.Error.getDescription(e));
      actionForward = mapping.findForward("same");
    }
    finally { if (j != null) {
          j.close();
        }
            } return actionForward;
  }
  private void insert_action(JdbcUtil j, ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) throws Exception {
    HttpSession session = request.getSession(true);
    CargoFuncionarioActionForm f = (CargoFuncionarioActionForm) form;
    br.com.werp.suporte.dbobj.table.Tipo_cargo_funcionario table =
      new br.com.werp.suporte.dbobj.table.Tipo_cargo_funcionario();
    Object[][] name_value = { {"Tcfn_descricao",f.getTcfn_descricao()}, };
    j.insert(table, name_value);
    session.setAttribute("CargoFuncionarioActionForm",
        new CargoFuncionarioActionForm());
    Vector res_Tipo_cargo_funcionario = (Vector) session.getAttribute("res_Tipo_cargo_funcionario");
    if (res_Tipo_cargo_funcionario != null && table != null) {
      res_Tipo_cargo_funcionario.addElement(table);
      session.setAttribute("res_Tipo_cargo_funcionario",
          res_Tipo_cargo_funcionario);
    }
  }

  public ActionForward perform_resetfull_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    try {
      session.removeAttribute("res_Tipo_cargo_funcionario");
      form.reset(mapping, request);
      session.setAttribute(mapping.getName(), form);
      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              com.egen.util.system.Error.getMessage(e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          com.egen.util.system.Error.getDescription(e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

}
